package org.sysmhg.base.service.impl;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.sysmhg.base.dao.CustomerDAO;
import org.sysmhg.base.model.Customer;
import org.sysmhg.base.service.CustomerService;
import org.sysmhg.util.Constants;
import org.sysmhg.util.GenericUtil;
import org.sysmhg.util.Pagination;

@SuppressWarnings("unchecked")
public class CustomerServiceImpl implements CustomerService{
	@SuppressWarnings("unused")
	private CustomerDAO customerDAO;


	public void setCustomerDAO(CustomerDAO customerDAO) {
		this.customerDAO = customerDAO;
	}
	
	public List getCustomers(Customer customer ,Pagination paginacion) {
		return customerDAO.getCustomers(customer, paginacion);
	}

	public Customer getCustomer(Customer customer) {
		return customerDAO.getCustomer(customer);
	}

	public void createCustomer(Customer Customer) {
		customerDAO.createCustomer(Customer);
	}

	public void updateCustomer(Customer customer) {
		customerDAO.updateCustomer(customer);
	}
	
	public void deleteCustomer(Customer customer) {
		customerDAO.deleteCustomer(customer);
	}
	
	public void deleteNCustomer(String strCustomerIds) {
		strCustomerIds = StringUtils.removeEnd(strCustomerIds, ",");
		GenericUtil.validateInputWithPattern(strCustomerIds,Constants.patternStringIdsToDelete);
		String[] tokensIds = strCustomerIds.split(",");
		for (String customerId : tokensIds) {
			Customer customer = new Customer();
			customer.setCustomer_id(GenericUtil.getDefaultLong(customerId));
			this.deleteCustomer(customer);
		}		
	}
	
}
